
package com.ami.kvm.jviewer.gui;

import com.ami.iusb.CDROMRedir;
import com.ami.iusb.FloppyRedir;
import com.ami.iusb.HarddiskRedir;
import com.ami.iusb.IUSBRedirSession;
import com.ami.kvm.jviewer.Debug;
import com.ami.kvm.jviewer.JViewer;
import com.ami.kvm.jviewer.common.ISOCFrameHdr;
import com.ami.kvm.jviewer.kvmpkts.KVMClient;
import com.ami.kvm.jviewer.videorecord.VideoRecordApp;
import com.ami.vmedia.VMApp;
import com.ami.vmedia.gui.DeviceControlPanel;
import com.ami.vmedia.gui.VMDialog;
import com.ami.vmedia.gui.VMPane;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Hashtable;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import javax.swing.plaf.basic.BasicInternalFrameUI;

public abstract class JVFrame extends JInternalFrame {
	protected JScrollPane m_viewSP;
	protected static String m_serverIP;
	private FSMenuBar m_fsMenuBr = new FSMenuBar();
	public JDialog videoStopError = null;
	private JLabel confirmationLabel = null;

	public JVFrame() {
		super(LocaleStrings.getString("C_1_JVF"), true, true, true, true);
	}

	public abstract JVMenu getMenu();

	public abstract void setStatus(String paramString);

	public abstract void resetStatus();

	public abstract void exitApp();

	public abstract void setWndLabel(String paramString);

	public abstract void refreshTitle();

	public static void setServerIP(byte[] paramArrayOfByte, int paramInt) {
		try {
			if ((paramArrayOfByte == null) && (paramInt == JViewerApp.REDIR_PAUSING)) {
				m_serverIP = LocaleStrings.getString("C_2_JVF");
			} else if ((paramArrayOfByte == null) && (paramInt == JViewerApp.REDIR_STOPPING)) {
				m_serverIP = LocaleStrings.getString("C_3_JVF");
			} else if ((paramArrayOfByte == null) && (JViewer.isplayerapp())) {
				m_serverIP = LocaleStrings.getString("C_4_JVF");
			} else if ((paramArrayOfByte == null) && (JViewer.isdownloadapp())) {
				m_serverIP = LocaleStrings.getString("C_5_JVF");
			} else
				m_serverIP = InetAddress.getByAddress(paramArrayOfByte).getHostAddress();
		} catch (UnknownHostException localUnknownHostException) {
			m_serverIP = LocaleStrings.getString("C_6_JVF");
			Debug.out.println(localUnknownHostException);
		}
	}

	public static String getServerIP() {
		if (m_serverIP != null) {
			if (!m_serverIP.equalsIgnoreCase(new String(LocaleStrings.getString("C_6_JVF")))) {
				return m_serverIP;
			}
		}
		return null;
	}

	public void attachView() {
		this.m_viewSP = new JScrollPane(JViewerApp.getInstance().getRCView());
		Dimension localDimension = Toolkit.getDefaultToolkit().getScreenSize();

		if (JViewerApp.getInstance().isM_wndMode()) {
			this.m_viewSP.getHorizontalScrollBar().setUnitIncrement(10);
			this.m_viewSP.getVerticalScrollBar().setUnitIncrement(10);
			JViewerApp.getInstance().getMainWindow().getContentPane().add(this.m_viewSP);
			getContentPane().setMaximumSize(localDimension);

			if (JViewer.isStandalone())
				JViewer.getMainFrame().setExtendedState(6);
			setVisible(true);
		}
		if (!JViewerApp.getInstance().isM_wndMode()) {
			if (JViewerApp.getInstance().getSocframeHdr().getresX() == localDimension.width) {
				this.m_viewSP.setHorizontalScrollBarPolicy(31);
			} else {
				this.m_viewSP.setHorizontalScrollBarPolicy(30);
			}
			if (JViewerApp.getInstance().getSocframeHdr().getresY() == localDimension.height) {
				this.m_viewSP.setVerticalScrollBarPolicy(21);
			} else {
				this.m_viewSP.setVerticalScrollBarPolicy(20);
			}
			JViewerApp.getInstance().getMainWindow().getContentPane().add(this.m_viewSP);

			if (JViewer.isStandalone())
				JViewer.getMainFrame().setExtendedState(6);
			setVisible(true);
		}
	}

	public static void setUndecorated(boolean paramBoolean, JInternalFrame paramJInternalFrame) {
		BasicInternalFrameUI localBasicInternalFrameUI = (BasicInternalFrameUI) paramJInternalFrame.getUI();
		if (paramBoolean) {
			paramJInternalFrame.putClientProperty("titlePane", localBasicInternalFrameUI.getNorthPane());
			paramJInternalFrame.putClientProperty("border", paramJInternalFrame.getBorder());
			localBasicInternalFrameUI.setNorthPane(null);
			paramJInternalFrame.setBorder(null);
		}
	}

	public void detachView() {
		this.m_fsMenuBr.cancelTimer();

		try {
			Thread.sleep(1L);
		} catch (InterruptedException localInterruptedException) {
			Debug.out.println(localInterruptedException);
		}
		getContentPane().remove(this.m_viewSP);
		dispose();
	}

	public boolean windowClosed() {
		if ((JViewer.isdownloadapp()) || (JViewer.isplayerapp())) {
			boolean bool = true;

			if (JViewerApp.getInstance().getConnectionDialog() != null) {

				bool = JViewerApp.getInstance().getConnectionDialog().isWebLogIn();
			}
			if (bool)
				JViewerApp.getInstance().getVideorecordapp().lockVideoFile(false);
			JViewerApp.getInstance().getVideorecordapp().Ondeletetmpfile();
		}

		if (JViewerApp.getInstance().GetRedirectionState() != JViewerApp.REDIR_STOPPED) {

			if (((JViewer.isjviewerapp()) || (JViewer.isStandAloneApp())) && (KVMShareDialog.isMasterSession)
					&& (JViewerApp.getInstance().getKVMShareDialog() != null)) {
				if ((JViewerApp.getInstance().getResponseDialogTable() != null)
						&& (!JViewerApp.getInstance().getResponseDialogTable().isEmpty())) {
					if (JViewerApp.getInstance().getKVMShareDialog().getDialogType() != 1) {
						JOptionPane.showMessageDialog(JViewerApp.getInstance().getMainWindow(),
								LocaleStrings.getString("C_14_JVF"), LocaleStrings.getString("C_15_JVF"), 1);

						return false;
					}
				}
			}
		}

		if (((JViewer.isjviewerapp()) || (JViewer.isStandAloneApp()))
				&& (!stopVMediaRedirection(LocaleStrings.getString("C_7_JVF")))) {
			if (JViewer.isKVMReconnectEnabled()) {
				JViewerApp.getInstance().setSessionLive(true);
			}
			return false;
		}

		if (JViewerApp.getInstance().getM_videorecord() != null) {
			if (VideoRecord.Recording_Started)
				JViewerApp.getInstance().getM_videorecord().OnVideoRecordStop();
			if (VideoRecord.Record_Processing) {
				if (JViewer.isdownloadapp())
					JViewerApp.getInstance().getVideorecordapp().disposeInformationDialog();
				showVideoStopError();
				while (VideoRecord.Record_Processing) {
					this.videoStopError.setVisible(true);
				}
			}
		}

		if (((JViewer.isjviewerapp()) || (JViewer.isStandAloneApp()))
				&& (JViewerApp.getInstance().GetRedirectionState() != JViewerApp.REDIR_STOPPED)) {
			JViewerApp.getInstance().OnSelectKVMMaster();
		}

		if (((JViewer.isjviewerapp()) || (JViewer.isStandAloneApp()))
				&& ((JViewer.getOEMFeatureStatus() & 0x200) != 512L)) {
			JViewerApp.getInstance().setClientKeyboardLEDStatus(JViewerApp.getInstance().getInitClientLEDStatus());
		}
		try {
			JViewerApp.getInstance().OnVideoStopRedirection();
		} catch (Exception localException) {
			Debug.out.println(localException);
		}

		if (JViewer.isStandalone()) {
			if ((!JViewer.isWebPreviewer()) && (!JViewer.isBSODViewer())
					&& (!JViewerApp.getInstance().getKVMClient().isStopSignalRecieved())) {
				JViewer.exit(0);
			}
		} else {
			if (Debug.MODE == 0)
				Debug.out.closeLog();
			JViewerApp.getInstance().getMainWindow().dispose();
		}

		return true;
	}

	public void generalErrorMessage(String paramString1, String paramString2) {
		JOptionPane.showMessageDialog(this, paramString2, paramString1, 0);
	}

	public JScrollPane getM_viewSP() {
		return this.m_viewSP;
	}

	public void setM_viewSP(JScrollPane paramJScrollPane) {
		this.m_viewSP = paramJScrollPane;
	}

	private void showVideoStopError() {
		if (this.videoStopError == null) {
			JFrame localJFrame = JViewer.getMainFrame();
			this.videoStopError = new JDialog(localJFrame, true);
			this.videoStopError.setUndecorated(true);
			this.videoStopError.setSize(550, 100);
			this.videoStopError.setLocationRelativeTo(localJFrame);
			this.videoStopError.setTitle(LocaleStrings.getString("C_11_JVF"));
			this.videoStopError.add(getVideoStopError());
			this.videoStopError.setVisible(true);
		}
	}

	private JPanel getVideoStopError() {
		JPanel localJPanel = new JPanel();
		localJPanel.setLayout(new FlowLayout(1, 2, 30));
		localJPanel.setSize(550, 100);
		JLabel localJLabel = new JLabel(
				LocaleStrings.getString("C_12_JVF") + JViewer.getTitle() + LocaleStrings.getString("C_13_JVF"));

		localJPanel.add(localJLabel);
		return localJPanel;
	}

	public JLabel getConfirmationLabel() {
		return this.confirmationLabel;
	}

	public void paintComponent(Graphics paramGraphics) {
		if (JViewer.isStandalone())
			setUndecorated(true, this);
		super.paintComponent(paramGraphics);
	}

	public boolean stopVMediaRedirection(String paramString) {
		if ((JViewerApp.getInstance().GetRedirectionState() != JViewerApp.REDIR_STOPPED) && (paramString != null)
				&& ((JViewerApp.getInstance().IsCDROMRedirRunning())
						|| (JViewerApp.getInstance().IsFloppyRedirRunning())
						|| (JViewerApp.getInstance().IsHarddiskRedirRunning()))) {

			if (JViewer.getMediaLicenseStatus() != 1) {
				InfoDialog.showDialog(JViewer.getMainFrame(), paramString, LocaleStrings.getString("A_6_GLOBAL"), 1);
			} else {
				this.confirmationLabel = new JLabel(paramString);
				UIManager.put("Button.defaultButtonFollowsFocus", Boolean.TRUE);
				int i = JOptionPane.showConfirmDialog(JViewer.getMainFrame(), this.confirmationLabel,
						LocaleStrings.getString("C_8_JVF"), 0);

				if (i == -1) {

					return false;
				}
				if (i == 1) {
					Debug.out.println("Returning false\n");
					return false;
				}
			}
		}

		onStopVMediaRedirection(0);
		return true;
	}

	public void onStopVMediaRedirection(int paramInt) {
		int i = 0;
		int j = 0;
		int k = 0;

		i = VMApp.getInstance().getNumCD();
		j = VMApp.getInstance().getNumFD();
		k = VMApp.getInstance().getNumHD();
		int m = JViewerApp.getInstance().getCDPort();
		int n = JViewerApp.getInstance().getFDPort();
		int i1 = JViewerApp.getInstance().getHDPort();
		boolean bool = JViewerApp.getInstance().isM_bVMUseSSL();
		String str1 = JViewerApp.getInstance().getSessionToken();

		if ((paramInt == 0) && (JViewerApp.getInstance().getVMDialog() != null)) {
			JViewerApp.getInstance().getVMDialog().disposeVMDialog();
		}
		try {
			String str2;
			for (int i2 = 0; i2 < i; i2++) {
				if (VMApp.getInstance().getIUSBRedirSession().cdromSession[i2] != null) {
					if (paramInt == 1) {
						VMApp.getInstance().getIUSBRedirSession().cdromSession[i2].setCdReconnect(true);
					}

					VMApp.getInstance().getIUSBRedirSession().StopCDROMRedir(i2, 0);
					VMApp.getInstance().getIUSBRedirSession().updateCDToolbarButtonStatus(false);

					if (paramInt == 1) {
						str2 = VMApp.getInstance().getIUSBRedirSession().cdromSession[i2].getSourceDrive();
						VMApp.getInstance().getIUSBRedirSession().cdromSession[i2].setCdReconnect(false);

						if (VMApp.getInstance().getIUSBRedirSession().cdromSession[i2].isCdImageRedirected() == true) {
							VMApp.getInstance().getIUSBRedirSession().StartISORedir(str1, m, i2, bool, str2);
							VMApp.getInstance().getIUSBRedirSession().cdromSession[i2].setCdImageRedirected(true);
						} else {
							VMApp.getInstance().getIUSBRedirSession().StartCDROMRedir(str1, m, i2, bool, str2);
							VMApp.getInstance().getIUSBRedirSession().cdromSession[i2].setCdImageRedirected(false);
						}

						VMApp.getInstance().getIUSBRedirSession().updateCDToolbarButtonStatus(true);
						VMApp.getVMPane().getDeviceControlPanel(0, i2).updateDeviceControlPanel();
					}
				}
			}
			for (int i2 = 0; i2 < j; i2++) {
				if (VMApp.getInstance().getIUSBRedirSession().floppySession[i2] != null) {
					if (paramInt == 1) {
						VMApp.getInstance().getIUSBRedirSession().floppySession[i2].setFdReconnect(true);
					}

					VMApp.getInstance().getIUSBRedirSession().StopFloppyRedir(i2, 0);
					VMApp.getInstance().getIUSBRedirSession().updateFDToolbarButtonStatus(false);

					if (paramInt == 1) {
						str2 = VMApp.getInstance().getIUSBRedirSession().floppySession[i2].getSourceDrive();
						VMApp.getInstance().getIUSBRedirSession().floppySession[i2].setFdReconnect(false);

						if (VMApp.getInstance().getIUSBRedirSession().floppySession[i2].isFdImageRedirected() == true) {
							VMApp.getInstance().getIUSBRedirSession().StartFloppyImageRedir(str1, n, i2, bool, str2);
							VMApp.getInstance().getIUSBRedirSession().floppySession[i2].setFdImageRedirected(true);
						} else {
							VMApp.getInstance().getIUSBRedirSession().StartFloppyRedir(str1, n, i2, bool, str2);
							VMApp.getInstance().getIUSBRedirSession().floppySession[i2].setFdImageRedirected(false);
						}
						VMApp.getInstance().getIUSBRedirSession().updateFDToolbarButtonStatus(true);
						VMApp.getVMPane().getDeviceControlPanel(1, i2).updateDeviceControlPanel();
					}
				}
			}
			for (int i2 = 0; i2 < k; i2++) {
				if (VMApp.getInstance().getIUSBRedirSession().hardDiskSession[i2] != null) {
					if (paramInt == 1) {
						VMApp.getInstance().getIUSBRedirSession().hardDiskSession[i2].setHdReconnect(true);
					}

					VMApp.getInstance().getIUSBRedirSession().StopHarddiskRedir(i2, 0);
					VMApp.getInstance().getIUSBRedirSession().updateHDToolbarButtonStatus(false);

					if (paramInt == 1) {
						str2 = VMApp.getInstance().getIUSBRedirSession().hardDiskSession[i2].getSourceDrive();
						VMApp.getInstance().getIUSBRedirSession().hardDiskSession[i2].setHdReconnect(false);
						byte b;
						if (VMApp.getInstance().getIUSBRedirSession().hardDiskSession[i2]
								.isHdImageRedirected() == true) {
							b = Byte.MIN_VALUE;
							VMApp.getInstance().getIUSBRedirSession().StartharddiskImageRedir(str1, i1, i2, bool, str2,
									b);
							VMApp.getInstance().getIUSBRedirSession().hardDiskSession[i2].setHdImageRedirected(true);
						} else {
							b = VMApp.getInstance().getIUSBRedirSession().getMediaType(str2);
							VMApp.getInstance().getIUSBRedirSession().StartHarddiskRedir(str1, i1, i2, bool, str2, b);
							VMApp.getInstance().getIUSBRedirSession().hardDiskSession[i2].setHdImageRedirected(false);
						}
						VMApp.getInstance().getIUSBRedirSession().updateHDToolbarButtonStatus(true);
						VMApp.getVMPane().getDeviceControlPanel(2, i2).updateDeviceControlPanel();
					}
				}
			}
		} catch (Exception localException) {
			Debug.out.println(localException);
		}
	}
}

/*
 * Location:
 * D:\Users\tianlin\Downloads\JViewer.jar!\com\ami\kvm\jviewer\gui\JVFrame.class
 * Java compiler version: 5 (49.0) JD-Core Version: 0.7.1
 */